"use strict";
cc._RF.push(module, '0b4492A2GVCRq0wq3EJCT0z', 'GiftBoxMgr');
// scripts/GiftBoxMgr.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("DataMgr"),
    i = e("VideoHint"),
    a = cc._decorator,
    r = a.ccclass,
    s = a.property,
    c = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.giftNodeParent = null;
    t.giftNodes = [];
    t.targetTime = 0;
    t.restTime = 0;
    t.openGiftPanel = null;
    t.timerLabel = null;
    return t;
  }

  n = t;

  t.prototype.onLoad = function () {
    n.Instance = this;
    cc.sys.localStorage.getItem("HasUseAddSpeed") || cc.sys.localStorage.setItem("HasUseAddSpeed", "false");
    cc.sys.localStorage.getItem("GiftTime") || cc.sys.localStorage.setItem("GiftTime", 0);
  };

  t.prototype.start = function () {
    if (!o["default"].Instance.hasSkin(2) && SDK.Mgr.Inst.hasAds) {
      this.giftNodes[0].active = !0;
      this.giftNodes[1].active = !1;
      this.giftNodes[2].active = !1;
      var e = this.giftNodes[0].getChildByName("Box");
      e.stopAllActions();
      var t = cc.rotateTo(.15, 15).easing(cc.easeSineInOut()),
          n = cc.rotateTo(.15, -15).easing(cc.easeSineInOut()),
          i = cc.rotateTo(.15, 15).easing(cc.easeSineInOut()),
          a = cc.rotateTo(.15, -15).easing(cc.easeSineInOut()),
          r = (a = cc.rotateTo(.15, 0).easing(cc.easeSineInOut()), cc.delayTime(2)),
          s = cc.repeatForever(cc.sequence(t, n, i, a, r));
      e.runAction(s);
    }
  };

  t.prototype.update = function () {
    this.giftNodes[1].active && (this.timerLabel.string = this.formatTimeFull(this.restTime));
  };

  t.prototype.getCurTimeSecends = function () {
    var e = new Date();
    return Math.floor(e.getTime() / 1e3);
  };

  t.prototype.formatTimeFull = function (e) {
    var t = Math.floor(e / 3600),
        n = Math.floor((e - 3600 * t) / 60),
        o = e - 3600 * t - 60 * n;
    return t.toString() + ":" + ("0" + n).substr(-2) + ":" + ("0" + o).substr(-2);
  };

  t.prototype.FreshBox = function () {
    if (!o["default"].Instance.hasSkin(2)) {
      this.targetTime = parseInt(cc.sys.localStorage.getItem("GiftTime"));
      var e = this.getCurTimeSecends();

      if (0 == this.targetTime) {
        this.giftNodes[0].active = !0;
        this.giftNodes[1].active = !1;
        this.giftNodes[2].active = !1;
      } else if (this.targetTime > e) {
        this.giftNodes[0].active = !1;
        this.giftNodes[1].active = !0;
        this.giftNodes[2].active = !1;
        this.restTime = this.targetTime - e;
      } else {
        this.giftNodes[0].active = !1;
        this.giftNodes[1].active = !1;
        this.giftNodes[2].active = !0;
      }
    }
  };

  t.prototype.ShowBox = function () {
    !o["default"].Instance.hasSkin(2) && SDK.Mgr.Inst.hasAds && (this.giftNodeParent.active = !0);
  };

  t.prototype.HideBox = function () {
    this.giftNodeParent.active = !1;
  };

  t.prototype.getGiftClickForAd = function () {
    var e = this,
        t = "OpenGift_Ad";
    SDK.Mgr.Inst.event(t + "Click");

    var n = function n(o) {
      if (o == SDK.Define.AdsCode.finish) {
        SDK.Mgr.Inst.event(t + "Success");
        cc.sys.localStorage.setItem("HasUseAddSpeed", "true");
        e.openGiftClick();
      } else if (o == SDK.Define.AdsCode.cancel) {
        SDK.Mgr.Inst.event(t + "Cancel");
        i["default"].Instance.openPanel(n);
      } else {
        SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
        SDK.Mgr.Inst.event(t + "NoAd");
      }
    };

    SDK.Mgr.Inst.showVideo(n);
  };

  t.prototype.getGiftClick = function () {
    SDK.Mgr.Inst.event("openGiftFree");
    cc.sys.localStorage.setItem("GiftTime", this.getCurTimeSecends() + 7200);
    this.targetTime = parseInt(cc.sys.localStorage.getItem("GiftTime"));
    this.FreshBox();
  };

  t.prototype.addSpeedClick = function () {
    var e = this,
        t = "AddSpeed_Ad";
    SDK.Mgr.Inst.event(t + "Click");

    var n = function n(o) {
      if (o == SDK.Define.AdsCode.finish) {
        SDK.Mgr.Inst.event(t + "Success");
        e.targetTime = parseInt(cc.sys.localStorage.getItem("GiftTime"));
        e.targetTime -= 1800;
        cc.sys.localStorage.setItem("GiftTime", e.targetTime);
        e.FreshBox();
        cc.sys.localStorage.setItem("HasUseAddSpeed", "true");
        SDK.ToastMgr.Inst.showToast("加速成功");
      } else if (o == SDK.Define.AdsCode.cancel) {
        SDK.Mgr.Inst.event(t + "Cancel");
        i["default"].Instance.openPanel(n);
      } else {
        SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
        SDK.Mgr.Inst.event(t + "NoAd");
      }
    };

    SDK.Mgr.Inst.showVideo(n);
  };

  t.prototype.openGiftClick = function () {
    this.openGiftPanel.active = !0;

    if ("true" == cc.sys.localStorage.getItem("HasUseAddSpeed")) {
      this.openGiftPanel.getChildByName("Panel").getChildByName("GetBtn1").active = !0;
      this.openGiftPanel.getChildByName("Panel").getChildByName("GetBtn2").active = !1;
    } else {
      this.openGiftPanel.getChildByName("Panel").getChildByName("GetBtn1").active = !1;
      this.openGiftPanel.getChildByName("Panel").getChildByName("GetBtn2").active = !0;
    }
  };

  t.prototype.getSkinBtnClick = function () {
    this.openGiftPanel.active = !1;
    this.unscheduleAllCallbacks();
    this.HideBox();
    SDK.Mgr.Inst.event("MicSkinSuccess");
    o["default"].Instance.setSkin(2, !0);
    o["default"].Instance.curSkinNum = 2;

    if (null != KillerController.Instance) {
      KillerController.Instance.freshSkin();
      SDK.ToastMgr.Inst.showToast("获得棒球棍武器");
    }
  };

  t.prototype.getSkinBtnAdClick = function () {
    var e = this,
        t = "GetSkin_Ad";
    SDK.Mgr.Inst.event(t + "Click");

    var n = function n(o) {
      if (o == SDK.Define.AdsCode.finish) {
        SDK.Mgr.Inst.event(t + "Success");
        e.getSkinBtnClick();
      } else if (o == SDK.Define.AdsCode.cancel) {
        SDK.Mgr.Inst.event(t + "Cancel");
        i["default"].Instance.openPanel(n);
      } else {
        SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
        SDK.Mgr.Inst.event(t + "NoAd");
      }
    };

    SDK.Mgr.Inst.showVideo(n);
  };

  t.prototype.closeSkinPanel = function () {
    this.openGiftPanel.active = !1;
  };

  var n;
  t.Instance = null;

  __decorate([s(cc.Node)], t.prototype, "giftNodeParent", void 0);

  __decorate([s([cc.Node])], t.prototype, "giftNodes", void 0);

  __decorate([s(cc.Node)], t.prototype, "openGiftPanel", void 0);

  __decorate([s(cc.Label)], t.prototype, "timerLabel", void 0);

  return n = __decorate([r], t);
}(cc.Component);

n["default"] = c;

cc._RF.pop();